{% extends 'base.html' %}
{% include 'link_css.html' %}
{% block content %}


<div class="text-center">
    <form class="col-lg-12" action="{% url 'goConfResult' %}" method="post">


        <div class="input-group my-group text-center" style="margin: 0px 0px 100px;">
            <span class="input-group-btn">
                <button class="btn btn-default active" type="submit">运行环境</button>
            </span>
            <select id="env" class="selectpicker form-control" data-live-search="true" name="env" onchange="getoption(this.value)">
                <option value="none"></option>
                <option value="1">生产环境</option>
                <option value="2">测试环境</option>
            </select>
        </div>


        <div class="input-group my-group text-center">
            <span class="input-group-btn">
                <button class="btn btn-default active" type="button">项目名称</button>
            </span>
            <select id="project" class="selectpicker form-control" data-live-search="true" name="project">

            </select>
        </div>

        <br/>
        <input id="sub" class="btn btn-danger" type="submit" value="update" disabled="disabled">
    </form>


</div>


<script>
    function getoption(val) {

        var project = document.getElementById("project")
        var env = document.getElementById("env").value;

        console.log(env)

        project.options.length = 0;   // del options
        if (env != "none") {
            $.getJSON("/asset/getConfProject",{"env":env},function (result) {
                console.log(result)
                for (i=0;i<result.length;i++) {
                    var objOption = document.createElement("OPTION")
                    objOption.value = result[i]
                    objOption.text = result[i]
                    project.add(objOption)
                }
                if (result.length != 0) {
                    $("#sub").attr("disabled", false)
                }
                else{
                    $("#sub").attr("disabled", true)
                }
                console.log(result.length)
            })
        }
        else{
            $("#sub").attr("disabled", true)
        }

    }
</script>

{% endblock %}
